package com.nowcoder.community.event;

import com.alibaba.fastjson2.JSONObject;
import com.nowcoder.community.entity.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * @author cjh
 * @date 2023/1/26 - 14:23
 */
@Component
public class EventProducer {
    @Autowired
    private KafkaTemplate kafkaTemplate;


    /**
     * 处理事件
     */
    public void fireEvent(Event event) {
//        将事件发送到指定主题
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
    }
}
